package k.index.Controller.feign;

import aj.org.objectweb.asm.TypeReference;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yc.bean.Result;
import k.daimai.entity.DmCategory;
import k.daimai.entity.DmProduct;
import k.daimai.entity.DmUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@Component
@Slf4j
public class OrderHystrix implements OrderFeign {
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    ObjectMapper objectMapper;
    @Override
    public List<DmProduct> queryHots() throws JsonProcessingException {
        String productListJson = (String) redisTemplate.opsForValue().get("hots");
        List<DmProduct> productList =objectMapper.readValue(productListJson,List.class);
        log.info("productListJson:{}", productListJson);
        return productList;
    }

    @Override
    public List<DmCategory> queryCategories() {
        return List.of();
    }

    @Override
    public int add(@RequestParam("a") int a, @RequestParam("b") int b) {
        return a+b+100;
    }

    @Override
    public Result getResult(Result result) {
        result.setMessage("熔断");
        return result;
    }

    @Override
    public DmUser getDmUser(DmUser user, String myname) {
        user.setCname("熔断name");
        return user;
    }

    @Override
    public String hello(String name) {
        return "hello 熔断" + name;
    }
}
